// 优惠券
import request from '@/utils/request'

// 优惠券列表
export function reqCouponList(page: number) {
  return request({
    url: `/admin/coupon/${page}`,
    method: 'get'
  })
}

// 删除
export function reqDeleteCoupon(ids: number | number[]) {
  if (Array.isArray(ids)) {
    return request({
      url: `/admin/coupon/delete_all`,
      method: 'post',
      data: { ids }
    })
  } else {
    return request({
      url: `/admin/coupon/${ids}/delete`,
      method: 'post'
    })
  }
}

// 新增
export function reqAddCoupon(data: {
  name: string
  type: number
  value: number
  total: number
  min_price: number
  start_time: string
  end_time: string
  order: number
}) {
  return request({
    url: '/admin/coupon',
    method: 'post',
    data
  })
}

// 修改
export function reqUpdateCoupon(
  id: number,
  data: {
    name: string
    type: number
    value: number
    total: number
    min_price: number
    start_time: string
    end_time: string
    order: number
  }
) {
  return request({
    url: `/admin/coupon/${id}`,
    method: 'post',
    data
  })
}

// 修改状态
export function reqUpdateCouponStatus(id: number, status: number = 0) {
  return request({
    url: `/admin/coupon/${id}/update_status`,
    method: 'post',
    data: {
      status
    }
  })
}
